package cn.bgs.service.impl;

import cn.bgs.common.R;
import cn.bgs.pageUtil.MybatisPageHelper;
import cn.bgs.pageUtil.PageRequest;
import cn.bgs.pageUtil.PageResult;
import cn.bgs.pojo.VehicleArea;
import cn.bgs.mapper.VehicleAreaMapper;
import cn.bgs.service.IVehicleAreaService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.bgs.vo.AreaVo;
import cn.bgs.vo.CommunityVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 车位区域表 服务实现类
 * </p>
 *
 * @author cf
 * @since 2022-06-07
 */
@Service
public class VehicleAreaServiceImpl extends ServiceImpl<VehicleAreaMapper, VehicleArea> implements IVehicleAreaService {
    @Autowired
    private VehicleAreaMapper vehicleAreaMapper;
    @Override
    public R carAreaList(PageRequest pageRequest) {
        MybatisPageHelper.startPage(pageRequest);
        PageResult list = MybatisPageHelper.getPageResult( vehicleAreaMapper.carAreaList());
        return R.ok().data("data",list);
    }

    @Override
    public Object carDelete(Integer id) {
        int carDelete = vehicleAreaMapper.carDelete(id);
        if (carDelete>0){
            return true;
        }
        return false;
    }

    @Override
    public List<VehicleArea> appFindVehicleArea(Integer communityId) {

        QueryWrapper<VehicleArea> wrapper = new QueryWrapper<>();

        wrapper.eq("community_id",communityId);

        return list(wrapper);
    }

    @Override
    public R pcAddCar(VehicleArea vehicleArea) {
        VehicleArea vca = new VehicleArea();
        vca.setVehicleAreaId(vehicleArea.getVehicleAreaId());
//        vca.setCommunityId(vehicleArea.getCommunityId());
        vca.setArea(vehicleArea.getArea());
        vca.setSize(vehicleArea.getSize());
        vca.setNumber(vehicleArea.getNumber());
        vca.setRemark(vehicleArea.getRemark());
//        vca.setCreateTime(vehicleArea.getCreateTime());
//        vca.setUpdateTime(vehicleArea.getUpdateTime());
        int i = vehicleAreaMapper.pcAddCar(vca);
        return R.ok();
    }

    @Override
    public R selectAreaInfo(AreaVo areaVo) {
        MybatisPageHelper.startPage(areaVo.getPageRequest());
        PageResult pageResult = MybatisPageHelper.getPageResult(vehicleAreaMapper.selectAreaInfo(areaVo));
        return R.ok().data("data",pageResult);
    }

    @Override
    public boolean updateAreaInfo(VehicleArea vehicleArea) {
        int i = vehicleAreaMapper.updateAreaInfo(vehicleArea);
        if (i>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean addAreaInfo(VehicleArea vehicleArea) {
        boolean a = vehicleAreaMapper.addAreaInfo(vehicleArea);
        return a;
    }

    @Override
    public R deleteCarInfo(Integer vehicleAreaId) {
        int delete = vehicleAreaMapper.deleteCarInfo(vehicleAreaId);
        return R.ok().data("delete", delete);
    }

    @Override
    public R info(CommunityVo communityVo) {
        List<VehicleArea> list = vehicleAreaMapper.info(communityVo);

        return R.ok().data("data",list);
    }

    @Override
    public R selectCarInfo(PageRequest request) {
        MybatisPageHelper.startPage(request);
        PageResult pageResult = MybatisPageHelper.getPageResult(vehicleAreaMapper.selectCarInfo(request));
        return R.ok().data("data",pageResult);
    }

}
